﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;
using System.Drawing;
using MyBusiness;

/// <summary>
/// 添加web页面的后台
/// </summary>
public partial class ManageInside_WebPubManager : Page
{
    string type = string.Empty;
    WebInfoOperation wifOperation = new WebInfoOperation();

    protected void Page_Load(object sender, EventArgs e)
    {
        labMsg.Text = Request.QueryString["type"];
        if (!IsPostBack)
        {
            if (Request["action"] == "modify")
            {
                DataTable dt = wifOperation.GetPubInfo(Request["id"]);

                if (dt.Rows.Count > 0)
                {
                    this.txt_title.Text = dt.Rows[0]["title"].ToString();
                    this.FreeTextBox1.Text = dt.Rows[0]["CONTENT"].ToString();
                }
            }
        }
    }

    /// <summary>
    /// 提交数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        UpdateData();
        Response.Redirect("More.aspx?type=" + Request.QueryString["type"]);
    }

    /// <summary>
    /// 调用前台javascript弹出信息并跳转页面
    /// </summary>
    /// <param name="mess">信息内容</param>
    /// <param name="url">跳转页面</param>
    protected void alertMessage(string mess)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "url", "alert('" + mess + "');", true);
    }

    /// <summary>
    /// 更新数据
    /// </summary>
    private void UpdateData()
    {
        try
        {
            string strSql = string.Empty;
            string sID = string.Empty;
            string title = this.txt_title.Text;
            string content = FreeTextBox1.Text;
           
            if (Request["action"] == "modify")
            {
                sID = Request["id"];
                wifOperation.UpdatePubInfo(title, sID, content);
            }
            else//不是修改就添加
            {
                sID = System.Guid.NewGuid().ToString().Replace("-", "");
                wifOperation.InsertPubInfo(title, sID, Request["type"], content);
            }
            alertMessage("操作成功！");

            //清空数据
            this.txt_title.Text = "";
            this.FreeTextBox1.Text = "";
        }
        catch (Exception ex)
        {
            alertMessage(ex.Message);
        }
    }

}
